using Dapper;
using FluentMigrator.Runner;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
using NLog.Web;
using Xunit.DependencyInjection.Logging;

namespace Crux.Core.Dapper.Test;
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        SqlMapper.AddTypeHandler(new DateTimeOffsetHandler());

        services.AddLogging((builder) =>
        {
            builder.AddXunitOutput();
            builder.AddNLogWeb();
        });
        services.AddDapper();
        services.Configure<DapperConfig<TestContext>>(option =>
        {
            option.SqlProvider = SqlGenerator.SqlProvider.SQLite;
            option.Factory = () => new SqliteConnection("Data Source=test.db");
        });
        services.AddFluentMigratorCore()
            .ConfigureRunner(rb => rb
                    // Add SQLite support to FluentMigrator
                    .AddSQLite()
                    // Set the connection string
                    .WithGlobalConnectionString("Data Source=test.db")
                    // Define the assembly containing the migrations
                    .ScanIn(typeof(TestMigration).Assembly).For.Migrations())
            .AddLogging(lb => lb.AddFluentMigratorConsole());
    }

}